package com.liuqi.openai.keyword;

import java.util.List;

/**
 * 关键词提取器结果, 包含了匹配结果描述{@link AbstractKeywordExtractor.MatchResult}
 *
 * @author liuqi
 * @date 2025/8/3
 **/
public class DictionaryProxy extends Dictionary {

    /**
     * 匹配结果可能或提取到多个关键词
     */
    private final List<String> keywords;

    /**
     * 文本匹配长度
     */
    private final int matchLength;

    /**
     * 检索次数
     */
    private final int searchCount;

    /**
     * 是否模仿匹配
     */
    final boolean fuzzy;

    public DictionaryProxy(String keyword,
                           String posTag,
                           String[] related,
                           boolean stop,
                           List<String> keywords,
                           int matchLength,
                           int searchCount,
                           boolean fuzzy) {
        super(keyword, posTag, related, stop);
        this.keywords = keywords;
        this.matchLength = matchLength;
        this.searchCount = searchCount;
        this.fuzzy = fuzzy;
    }

    public static DictionaryProxyBuilder builder() {
        return new DictionaryProxyBuilder();
    }

    public static class DictionaryProxyBuilder {
        private String keyword;
        private String posTag;
        private String[] related;
        private List<String> keywords;
        private int matchLength;
        private int searchCount;
        private boolean fuzzy;

        DictionaryProxyBuilder() {
        }

        public DictionaryProxyBuilder keyword(String keyword) {
            this.keyword = keyword;
            return this;
        }

        public DictionaryProxyBuilder posTag(String posTag) {
            this.posTag = posTag;
            return this;
        }

        public DictionaryProxyBuilder related(String[] related) {
            this.related = related;
            return this;
        }

        public DictionaryProxyBuilder keywords(List<String> keywords) {
            this.keywords = keywords;
            return this;
        }

        public DictionaryProxyBuilder matchLength(int matchLength) {
            this.matchLength = matchLength;
            return this;
        }

        public DictionaryProxyBuilder searchCount(int searchCount) {
            this.searchCount = searchCount;
            return this;
        }

        public DictionaryProxyBuilder fuzzy(boolean fuzzy) {
            this.fuzzy = fuzzy;
            return this;
        }

        public DictionaryProxy build() {
            return new DictionaryProxy(
                    this.keyword,
                    this.posTag,
                    this.related,
                    false,
                    this.keywords,
                    this.matchLength,
                    this.searchCount,
                    this.fuzzy
            );
        }
    }

    public List<String> getKeywords() {
        return keywords;
    }

    public int getMatchLength() {
        return matchLength;
    }

    public int getSearchCount() {
        return searchCount;
    }

    public boolean isFuzzy() {
        return fuzzy;
    }

    public String toString() {
        return "DictionaryProxy(super=" + super.toString() +
                ", keywords=" + this.getKeywords() +
                ", matchLength=" + this.getMatchLength() +
                ", searchCount=" + this.getSearchCount() +
                ", fuzzy=" + this.isFuzzy() + ")";
    }
}
